package org.example.sensor.controller;

import io.swagger.v3.oas.annotations.Operation;
import lombok.RequiredArgsConstructor;

import org.example.sensor.dox.User;
import org.example.sensor.service.UserService;
import org.example.sensor.vo.ResultVO;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("api/admin/")
@RequiredArgsConstructor
public class AdminController {
    private final UserService userService;



    //添加user
    @Operation(summary = "添加user",description = "只需输入名字，账号，角色即可")
    @PostMapping("user")
    public ResultVO postUser(@RequestBody User user) {
        userService.addUser(user);
        return ResultVO.ok();
    }
    //重置密码
    @Operation(summary = "重置用户的密码",description = "输入账号")
    @PutMapping("users/{account}/password")
    public ResultVO putPassword(@PathVariable String account) {
        userService.updateUserPassword(account);
        return ResultVO.ok();
    }
    //查看user
    @Operation(summary = "查看所有用户")
    @GetMapping("users")
    public ResultVO listUsers(){
        return ResultVO.success(userService.listUsers());
    }

    @Operation(summary = "删除用户/老师",description = "输入用户的账号,删除管理员的账号会出现报错")
    @DeleteMapping("delUser/{account}")
    public ResultVO delUser(@PathVariable String account) {
        userService.deleteUser(account);
        return ResultVO.success("成功删除");
    }
    @Operation(summary = "查询指定用户",description = "输入指定的account")
    @GetMapping("queryUser/{account}")
    public ResultVO queryUser(@PathVariable String account) {
        User user = userService.queryUser(account);
        return ResultVO.success(user);
    }






}
